Autocorrelation

Introduction

“Everything is related to everything else, but near things are more related than distant things.” -Waldo R. Tobler

Spatial autocorrelation is a way to measure how much things that are close to each other are similar or different. Imagine a usual rainy day in London. If it rains in one part of a town, it is also likely raining in nearby areas. This shows high spatial autocorrelation as weather in one place is similar to the weather in nearby places.

It is important to investigate spatial autocorrelation in each type of crime, particularly when we want to estimate risk of crime with place-based information. By analysing spatial autocorrelation, we can identify if there is any spatial pattern and hotspot for each type of crime.

Examples of Spatial Autocorrelation

(a) positive - clustering (b) negative - dispersion (c) random

The diagram1 above illustrate examples of spatial autocorrelation. Both (a) and (b) show some patterns, whereas with (c) we can’t explain how black and white boxes are located. Hence, (c) is completely random and shows no pattern, therefore, no autocorrelation.

For (a), we can also see black boxes are clustered at a corner. This is clustering, or positive autocorrleation. One of the common measures of spatial autocorrelation, Moran’s Index (or Moran’s I) is positive in the case of (a). With (b), we can see a checkerboard pattern. We can safely say (b) is dispersed, which has negative spatial autocorrelation, scoring negative on Moran’s I.

Set Up

Load packages and data

Code
#--Install / load packages
pacman::p_load(sf, here, tmap, osmdata, tidyverse, data.table, rio, flextable, mapview, units, knitr, spdep, deldir, sp, rgeoda)

#--Import street-level crime data
crime <- rio::import(here::here("3_output", "crime_2024-05-09.csv")) |>
    dplyr::mutate(category = stringr::str_replace_all(category, "-", " ")) |>
    sf::st_as_sf(coords = c("location.longitude", "location.latitude"), crs = 4326, dim = "XY") 
    #from 2021-04 to 2024-03

#--Import Barnet shapefile
bnt_shp <- sf::st_read(here("1_data", "9_geo", "bnt_lad.json"), crs = 4326) |>
  st_make_valid()
#> Reading layer `OS - BoundaryLine - 2022Authorities - Barnet' from data source 
#>   `C:\Users\Hannah.Chang\OneDrive - London Borough of Barnet\General - I&I Hub\02. Project Documentation\07. Standard Projects\ARC_LBB Website\arc_lbb_website\1_data\9_geo\bnt_lad.json' 
#>   using driver `TopoJSON'
#> Simple feature collection with 1 feature and 17 fields
#> Geometry type: POLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -0.3055738 ymin: 51.55528 xmax: -0.1291338 ymax: 51.67021
#> Geodetic CRS:  WGS 84

#--Filter crime that intersects Barnet boundary
crime_bnt <- crime[which(st_intersects(bnt_shp, crime, sparse = FALSE)),]

#--Reproject onto OSGB36
crime_bnt <- st_transform(crime_bnt, 27700)

Subset Data by Type of Crime

Code
#--Subset crime data 
asb <- subset(crime_bnt, category == "anti social behaviour")
vc <- subset(crime_bnt, category == "violent crime")
other <- subset(crime_bnt, category == "other theft")
vhc <- subset(crime_bnt, category == "vehicle crime")
tfp <- subset(crime_bnt, category == "theft from the person")
brg <- subset(crime_bnt, category == "burglary")

Global Spatial Autocorrelation

We will investigate if there is a spatial autocorrelation overall in each type of crime. First of all, we need to define neighbours as spatial autocorrelation is contingent on how we define neighbours. While there are many ways to do so, we will deinfe points as neighbours if they are within a certain distance. This distance is called critical threshold.

Create Distance-Based Weight

Example with ASB

Code
#--Get X and Y coordinates
asb_coords <- st_coordinates(asb)

#--To find a critical threshold, find the k-nearest neighbors for k = 1
knn1_asb <- knearneigh(asb_coords)

#--Convert k1 to nb
k1_asb <- knn2nb(knn1_asb)

#--Calculate critical threshold: maximum distance between neighbours
critical_threshold_asb <- max(unlist(nbdists(k1_asb, asb_coords)))

critical_threshold_asb
#> [1] 660.1971

#--Calculate distance-band weights
nb_dist_band_asb <- dnearneigh(asb_coords, 0, critical_threshold_asb)

summary(nb_dist_band_asb)
#> Neighbour list object:
#> Number of regions: 25551 
#> Number of nonzero links: 18578630 
#> Percentage nonzero weights: 2.845757 
#> Average number of links: 727.1195 
#> Link number distribution:
#> 
#>    1    2    4    6    7    8    9   12   15   16   18   22   23   26   27   28 
#>    3    2    4    1    7    1    1    2    5    3    6    2    2   24    9    4 
#>   30   31   32   33   34   35   36   37   38   39   40   42   43   44   46   48 
#>   26    6    2    4    2    2   25    1    2   30    3    6   38    2    5    5 
#>   49   50   51   55   57   60   62   63   65   66   67   68   69   70   71   72 
#>    6    8    4    4    1    2    2    6    1    5    1    1    7    4    1    4 
#>   73   74   75   76   77   78   80   82   83   86   91   92   94   98   99  100 
#>    3    1    2   23    3   10    2    2    6    9    1   13    7   10    4    2 
#>  101  103  105  106  107  108  109  110  111  112  113  114  115  116  117  118 
#>   17    2   10   43    1    5    3    4    5   27    2   23    7   23    7    1 
#>  119  120  121  122  123  125  126  127  128  129  130  131  132  133  134  135 
#>    4   11    6    3    6    1    9   20   14    2   18    2    9   14    7    5 
#>  137  138  139  140  141  143  146  150  152  153  156  157  158  159  160  162 
#>    7   17    7    4   11   13    7    4    2    4   16   19    1    3   68   13 
#>  164  165  167  168  169  171  173  174  175  176  178  179  180  181  182  183 
#>    1    1   10    5   12   12   32   11    5    8    1   14    8    2   18    4 
#>  184  185  186  187  188  189  190  191  192  193  195  196  197  198  199  200 
#>   10    8   15   15    1    2    8   22   19    5    5    6   20    7   14    2 
#>  201  202  203  204  205  206  207  208  209  210  211  212  213  214  215  216 
#>   25    7   22   39   14    6   26   10    2    3   16   21   11    7   41   16 
#>  217  218  219  220  221  222  223  224  225  227  228  229  230  231  232  233 
#>   16   16    8   37   24   62   35   25   12   18   18   11   10   26   13   42 
#>  234  235  236  237  238  239  240  241  242  243  244  245  246  247  248  249 
#>   43   10   23   25   11   22   29    6   11   24    8   34   14   21    2   23 
#>  250  251  252  253  254  255  256  257  258  259  260  261  262  263  264  265 
#>   15   55   30   11   13   11   43   10   43   33   23    5   43   31   39   63 
#>  266  267  268  269  270  271  272  273  274  275  276  277  278  279  280  281 
#>    3   22   52    3   42   35    5    4   40   16   50   46   46   47   27   44 
#>  282  283  284  285  286  287  288  289  290  291  292  293  294  295  296  297 
#>   18    8   26    7    9   20    6   23   37   44   62   13   58   22   83   53 
#>  298  299  300  301  302  303  304  305  306  307  308  309  310  311  312  313 
#>   12    8    3   31   18   41   33   16   11   17   22   16   55    7    4   65 
#>  314  315  316  317  318  319  320  321  322  323  324  325  326  327  328  329 
#>    7    3   11   18   18   18   15   13   21   21   11    2   10   19    3    5 
#>  330  331  332  333  334  335  336  337  338  339  340  341  342  343  344  345 
#>   24   13   23   14   37   21    1   30    9    2   25   73    2   46   33   12 
#>  346  347  348  349  350  351  352  353  354  355  356  357  358  359  360  361 
#>   52   24    9    4   53    2   16   11   12    2    1   27    2    5   20   19 
#>  362  363  364  365  366  367  368  369  370  372  373  374  375  376  377  378 
#>    1   23   24   10   85   33   26   12   56   45   18   63    3   27    9   27 
#>  379  380  381  382  383  384  385  386  387  388  389  390  391  392  393  394 
#>   31   35   55   20    8   13   33    3   85   83   40   13   81   32   24   64 
#>  395  396  397  398  399  400  401  402  403  404  405  406  407  408  409  410 
#>   12   17   46    6    7   16   12   25  122   52   47   90   17   32    5   42 
#>  411  412  413  414  416  417  418  419  420  421  422  424  425  426  427  428 
#>    3   75   19   19   29   85   66   34   38   38   21   15   15   29   68   18 
#>  429  430  431  432  433  434  435  436  437  438  439  440  441  442  443  444 
#>    9   30   11   37   28   50   13   12   14   13   14    9   24   50   34   37 
#>  445  446  447  448  449  450  451  452  453  454  455  456  457  458  459  460 
#>   26    6   14   53   16   10    2   41   41   42   23  189   28   38   25   15 
#>  461  462  463  464  465  466  467  468  469  470  471  472  473  474  475  476 
#>   16  233   23   19   59   34   30   94   67   28   35   18   17    4    6   15 
#>  477  478  479  480  481  482  483  484  485  486  487  488  489  490  491  492 
#>   61   12   48   48   68   44   26   67   20   31   11   11  177   10   84    8 
#>  493  494  495  496  497  498  499  500  501  502  503  504  505  506  507  508 
#>   37   41   17    8    2   29   10   19   51    8   65   63   51   65    8   15 
#>  509  510  511  512  513  514  515  516  517  518  519  520  521  522  523  524 
#>   41    9    3    8   20   23   19   10   42   26   15   18   19   16   28    5 
#>  525  526  527  528  529  530  531  532  533  534  535  536  537  538  539  540 
#>    6   39   17   16    2   23   33    1  119    5   22   59   29   32   42   14 
#>  541  542  543  544  545  546  547  548  549  550  551  552  553  554  555  556 
#>    2   38   51    3   69    2   30    7   74   29    8   17    9   34   11    4 
#>  557  558  559  560  561  562  563  564  565  566  567  568  569  570  571  572 
#>   18   20   57   30   54    4   71   48   10    3   21   44   41   18    9   12 
#>  573  574  575  576  577  578  579  580  581  582  583  584  585  586  587  588 
#>   20    3   22   35  141   38   19    2    4   30   11   15    5   16   17   15 
#>  589  590  591  592  593  594  595  596  597  598  599  600  603  604  606  607 
#>   29   39   15    5    6   15    8   24   16  146   11    9   18   21    1   61 
#>  608  611  613  614  615  616  618  619  620  621  622  623  624  625  626  628 
#>   57   43   65    1   10    9    2   19    2   22   77   56   10    6   56   10 
#>  629  630  631  632  633  634  635  636  637  638  639  642  643  644  645  646 
#>    6    4   22    3   66   51   12   23   47   58    3    4    4   39    3   15 
#>  647  648  649  650  651  652  653  654  655  656  657  658  659  660  661  662 
#>   41    1   16    1    2   42   36   11   15    4   22    1   17   11   28   20 
#>  663  664  665  666  667  668  669  670  671  673  674  675  676  677  678  680 
#>   36   16    7   10   93   70    3   13    2   41   52   40   10    7    9    7 
#>  681  682  683  684  685  686  687  688  689  690  691  693  694  696  697  698 
#>   23   14   12   15   21    7   17    6    1    4    2   28   23    4   61   15 
#>  699  701  702  703  704  705  706  708  709  710  711  713  714  716  717  719 
#>   65    1   35   45    5    1   18   23   19    4   58   51   30   25   17   14 
#>  720  721  722  723  725  726  727  728  729  730  731  732  733  734  735  736 
#>   20   14    7   12   39    5    1   12  101   11    3   11    2   45   26   13 
#>  738  739  740  741  742  743  744  745  746  747  748  749  750  751  753  754 
#>    2    2   16   27   10    3    3    4   44   23    1   55   89    3   27   32 
#>  755  756  757  758  760  761  763  764  765  766  767  768  769  770  771  772 
#>    3    7   12    2   61  134   28   27   22    7    1   20    4   16   22   40 
#>  773  776  777  778  779  781  782  783  784  785  786  787  788  789  790  791 
#>   43    3   16    5    5    6   16   12    5   59   85    7    3    1   27   24 
#>  792  793  794  795  796  797  798  799  800  801  803  804  805  806  808  809 
#>   37   22   11    6   14    3    5   13    2    7   22    1   25    6   28   29 
#>  810  811  812  813  814  815  816  817  818  819  820  822  823  824  825  826 
#>   16    1   14    8    7   25    2    4   26   53   61   20    8   30   13   58 
#>  827  828  829  830  831  832  834  835  836  837  839  840  842  843  844  845 
#>  113   27   59   31   58   13   84    1  386   35   21   30   20   11   20    5 
#>  846  847  849  850  851  852  853  854  857  858  859  860  861  862  863  864 
#>   13   26    6  175   11   42   63    4   14   28    7   35    4   13   10   63 
#>  865  866  867  868  869  870  871  872  873  874  875  876  877  878  879  880 
#>   19   27   18   39   27    2    5    9   47   40  114   25   10    9   14   11 
#>  881  882  883  884  885  887  888  889  890  892  893  894  895  896  897  898 
#>    5   21   15   13    6    2   34    2    7   55  212    3  144   13    7    5 
#>  899  900  901  902  903  904  905  906  907  908  909  910  913  914  915  916 
#>   25   17   17   51   20   10   19   46    5    2   27   22    4   11    4   31 
#>  918  919  920  921  922  923  924  925  926  927  928  929  932  933  934  935 
#>   97   69   21   22   78    9   38   23    5    3    2   27   48   11   18   10 
#>  937  938  939  941  942  943  949  952  953  954  957  958  959  961  962  963 
#>    9   11   26    2   31    5   11    2    6   15    6    2    5    8    8    7 
#>  970  975  976  977  978  981  982  983  985  987  988  991  992  997  999 1000 
#>    2    2    5    2   13    2    5    1   42    3    6    1    1   13    6   11 
#> 1001 1004 1005 1006 1007 1008 1010 1011 1013 1015 1017 1019 1027 1028 1029 1031 
#>    2    3    6    5   36    1   19    3   10    9   18   25    2    1    8   22 
#> 1032 1033 1034 1037 1038 1039 1040 1041 1043 1045 1046 1049 1051 1056 1061 1062 
#>   31    1    6    1    5   42   11    2    5   42    6   16    6    1   13    8 
#> 1066 1068 1069 1074 1078 1079 1080 1083 1085 1087 1090 1092 1093 1094 1095 1096 
#>    5  144  329   17    7    5    7    1    8   19   13   16    3   18   19   11 
#> 1097 1100 1102 1103 1106 1108 1109 1110 1111 1112 1114 1117 1120 1124 1125 1127 
#>    7  211    4   11    4  173    3   32    5   18    8  134   55    5    1    3 
#> 1128 1131 1134 1135 1136 1138 1139 1140 1141 1142 1143 1144 1145 1147 1149 1150 
#>    3   82   41   35    7   11   56    2   45   23   14   27    2    4  100   31 
#> 1151 1153 1154 1155 1157 1159 1161 1162 1164 1165 1166 1167 1168 1169 1171 1173 
#>   12  145    1   45    3    1    4   16    2   20    4   11    6   10    3   10 
#> 1174 1176 1178 1179 1183 1184 1186 1187 1189 1191 1192 1193 1194 1201 1203 1204 
#>    4    8  165   15    5    1    1    9   16    2   41   13    4   24    9    8 
#> 1205 1206 1210 1212 1213 1215 1218 1219 1220 1222 1227 1235 1237 1241 1244 1247 
#>    4    8   31    1    7    5    2   15    1    4   25   39    7    1    6    1 
#> 1251 1252 1256 1261 1263 1267 1270 1272 1275 1277 1284 1287 1288 1291 1294 1299 
#>    8    5   46    4    9   32    1    3    1    2   34    9    8   31   25   29 
#> 1302 1309 1313 1317 1322 1325 1328 1335 1339 1340 1341 1350 1351 1354 1361 1372 
#>    6    3    1   10    7   28   12   66    1    5    2   28   44    2   32    1 
#> 1387 1391 1392 1393 1396 1398 1400 1402 1403 1404 1406 1409 1410 1414 1415 1423 
#>    4   19    9   14   43   12    2    4   14  117   26    1    7    9    1   12 
#> 1424 1430 1432 1446 1449 1452 1453 1463 1472 1473 1475 1481 1482 1483 1484 1485 
#>   21    2    7    5    2    2   20   21    8    4    5   82    2   37    4    1 
#> 1487 1491 1520 1522 1524 1525 1530 1534 1536 1537 1546 1551 1552 1562 1568 1569 
#>   13    2    7    2    1   42   21    1    3   61   16    3    7   16   89   59 
#> 1570 1583 1584 1595 1605 1607 1613 1625 1626 1629 1634 1643 1651 1665 1668 1674 
#>   36    1    5    5    2   17   20    3   33  133    1   91    6   10    6   17 
#> 1688 1705 1722 1735 1744 1772 1780 1794 1820 1838 1844 1847 1850 1866 1867 1869 
#>   16   12    2    8    6    4   33    4    4   13   37   93   12   71    1   42 
#> 1886 1890 1896 1918 1922 1929 1939 1971 1984 1986 2006 2009 2012 2018 2027 2030 
#>   77   50   36    5   23    5   25   32   83   35    6   10    3   27    2   14 
#> 2034 2044 2064 2073 2079 2088 2089 2095 2097 2099 2100 2103 2109 2115 2117 2119 
#>    7    1   13   12    2    6    2   12   18   41   12   23    2    3   12    1 
#> 2123 2127 2140 2146 2148 2150 2156 2160 2172 2177 2220 2308 2316 2324 2334 
#>    2   17    1    1   38    8    2    4   10    6    2    2    1   11    5 
#> 3 least connected regions:
#> 10690 11508 23955 with 1 link
#> 5 most connected regions:
#> 1838 1839 2397 16552 21929 with 2334 links

#--Get cardinality: number of neighbours for each point
dist_band_card_asb <- spdep::card(nb_dist_band_asb)

#--Check number of neighbours
ggplot() +
  geom_histogram(aes(x=dist_band_card_asb)) +
  xlab("Number of Neighbours")+
  ggtitle("Connectivity Histogram")+
  theme_minimal()

Code

#--Create weight from nb
dist_weight_asb <- nb2listw(nb_dist_band_asb)

The critical threshold for ASB was 660m. That is, ASB points were considered neighbours #### Repeat ##### Define Function: create_dist_weight()

Code
create_dist_weight <- function(crime_type){
  #--Get X and Y coordinates
  coords <- st_coordinates(crime_type)

  #--To find a critical threshold, find the k-nearest neighbors for k = 1
  knn1 <- knearneigh(coords)

  #--Convert k1 to nb
  k1 <- knn2nb(knn1)

  #--Calculate critical threshold: maximum distance between neighbours
  critical_threshold <- max(unlist(nbdists(k1, coords)))

  print(paste0("Critical threshold is: ", critical_threshold, "m"))

  #--Calculate distance-band weights
  nb_dist_band <- dnearneigh(coords, 0, critical_threshold)

  summary(nb_dist_band)

  #--Get cardinality: number of neighbours for each point
  dist_band_card <- spdep::card(nb_dist_band)

  #--Create weight from nb
  dist_weight <- nb2listw(nb_dist_band)
  print("Done")
  return(dist_weight)
}

Loop

Code
#--Create list of crimes by type
l_crime <- list(asb, vc, other, vhc, tfp, brg)
names(l_crime) <- c("asb", "vc", "other", "vhc", "tfp", "brg")

#--Apply create_dist_weight()
l_weight <- vector("list", length(l_crime))
names(l_weight) <- names(l_crime)
l_weight <- lapply(l_crime, create_dist_weight)
#> [1] "Critical threshold is: 660.197061933469m"
#> Neighbour list object:
#> Number of regions: 25551 
#> Number of nonzero links: 18578630 
#> Percentage nonzero weights: 2.845757 
#> Average number of links: 727.1195 
#> Link number distribution:
#> 
#>    1    2    4    6    7    8    9   12   15   16   18   22   23   26   27   28 
#>    3    2    4    1    7    1    1    2    5    3    6    2    2   24    9    4 
#>   30   31   32   33   34   35   36   37   38   39   40   42   43   44   46   48 
#>   26    6    2    4    2    2   25    1    2   30    3    6   38    2    5    5 
#>   49   50   51   55   57   60   62   63   65   66   67   68   69   70   71   72 
#>    6    8    4    4    1    2    2    6    1    5    1    1    7    4    1    4 
#>   73   74   75   76   77   78   80   82   83   86   91   92   94   98   99  100 
#>    3    1    2   23    3   10    2    2    6    9    1   13    7   10    4    2 
#>  101  103  105  106  107  108  109  110  111  112  113  114  115  116  117  118 
#>   17    2   10   43    1    5    3    4    5   27    2   23    7   23    7    1 
#>  119  120  121  122  123  125  126  127  128  129  130  131  132  133  134  135 
#>    4   11    6    3    6    1    9   20   14    2   18    2    9   14    7    5 
#>  137  138  139  140  141  143  146  150  152  153  156  157  158  159  160  162 
#>    7   17    7    4   11   13    7    4    2    4   16   19    1    3   68   13 
#>  164  165  167  168  169  171  173  174  175  176  178  179  180  181  182  183 
#>    1    1   10    5   12   12   32   11    5    8    1   14    8    2   18    4 
#>  184  185  186  187  188  189  190  191  192  193  195  196  197  198  199  200 
#>   10    8   15   15    1    2    8   22   19    5    5    6   20    7   14    2 
#>  201  202  203  204  205  206  207  208  209  210  211  212  213  214  215  216 
#>   25    7   22   39   14    6   26   10    2    3   16   21   11    7   41   16 
#>  217  218  219  220  221  222  223  224  225  227  228  229  230  231  232  233 
#>   16   16    8   37   24   62   35   25   12   18   18   11   10   26   13   42 
#>  234  235  236  237  238  239  240  241  242  243  244  245  246  247  248  249 
#>   43   10   23   25   11   22   29    6   11   24    8   34   14   21    2   23 
#>  250  251  252  253  254  255  256  257  258  259  260  261  262  263  264  265 
#>   15   55   30   11   13   11   43   10   43   33   23    5   43   31   39   63 
#>  266  267  268  269  270  271  272  273  274  275  276  277  278  279  280  281 
#>    3   22   52    3   42   35    5    4   40   16   50   46   46   47   27   44 
#>  282  283  284  285  286  287  288  289  290  291  292  293  294  295  296  297 
#>   18    8   26    7    9   20    6   23   37   44   62   13   58   22   83   53 
#>  298  299  300  301  302  303  304  305  306  307  308  309  310  311  312  313 
#>   12    8    3   31   18   41   33   16   11   17   22   16   55    7    4   65 
#>  314  315  316  317  318  319  320  321  322  323  324  325  326  327  328  329 
#>    7    3   11   18   18   18   15   13   21   21   11    2   10   19    3    5 
#>  330  331  332  333  334  335  336  337  338  339  340  341  342  343  344  345 
#>   24   13   23   14   37   21    1   30    9    2   25   73    2   46   33   12 
#>  346  347  348  349  350  351  352  353  354  355  356  357  358  359  360  361 
#>   52   24    9    4   53    2   16   11   12    2    1   27    2    5   20   19 
#>  362  363  364  365  366  367  368  369  370  372  373  374  375  376  377  378 
#>    1   23   24   10   85   33   26   12   56   45   18   63    3   27    9   27 
#>  379  380  381  382  383  384  385  386  387  388  389  390  391  392  393  394 
#>   31   35   55   20    8   13   33    3   85   83   40   13   81   32   24   64 
#>  395  396  397  398  399  400  401  402  403  404  405  406  407  408  409  410 
#>   12   17   46    6    7   16   12   25  122   52   47   90   17   32    5   42 
#>  411  412  413  414  416  417  418  419  420  421  422  424  425  426  427  428 
#>    3   75   19   19   29   85   66   34   38   38   21   15   15   29   68   18 
#>  429  430  431  432  433  434  435  436  437  438  439  440  441  442  443  444 
#>    9   30   11   37   28   50   13   12   14   13   14    9   24   50   34   37 
#>  445  446  447  448  449  450  451  452  453  454  455  456  457  458  459  460 
#>   26    6   14   53   16   10    2   41   41   42   23  189   28   38   25   15 
#>  461  462  463  464  465  466  467  468  469  470  471  472  473  474  475  476 
#>   16  233   23   19   59   34   30   94   67   28   35   18   17    4    6   15 
#>  477  478  479  480  481  482  483  484  485  486  487  488  489  490  491  492 
#>   61   12   48   48   68   44   26   67   20   31   11   11  177   10   84    8 
#>  493  494  495  496  497  498  499  500  501  502  503  504  505  506  507  508 
#>   37   41   17    8    2   29   10   19   51    8   65   63   51   65    8   15 
#>  509  510  511  512  513  514  515  516  517  518  519  520  521  522  523  524 
#>   41    9    3    8   20   23   19   10   42   26   15   18   19   16   28    5 
#>  525  526  527  528  529  530  531  532  533  534  535  536  537  538  539  540 
#>    6   39   17   16    2   23   33    1  119    5   22   59   29   32   42   14 
#>  541  542  543  544  545  546  547  548  549  550  551  552  553  554  555  556 
#>    2   38   51    3   69    2   30    7   74   29    8   17    9   34   11    4 
#>  557  558  559  560  561  562  563  564  565  566  567  568  569  570  571  572 
#>   18   20   57   30   54    4   71   48   10    3   21   44   41   18    9   12 
#>  573  574  575  576  577  578  579  580  581  582  583  584  585  586  587  588 
#>   20    3   22   35  141   38   19    2    4   30   11   15    5   16   17   15 
#>  589  590  591  592  593  594  595  596  597  598  599  600  603  604  606  607 
#>   29   39   15    5    6   15    8   24   16  146   11    9   18   21    1   61 
#>  608  611  613  614  615  616  618  619  620  621  622  623  624  625  626  628 
#>   57   43   65    1   10    9    2   19    2   22   77   56   10    6   56   10 
#>  629  630  631  632  633  634  635  636  637  638  639  642  643  644  645  646 
#>    6    4   22    3   66   51   12   23   47   58    3    4    4   39    3   15 
#>  647  648  649  650  651  652  653  654  655  656  657  658  659  660  661  662 
#>   41    1   16    1    2   42   36   11   15    4   22    1   17   11   28   20 
#>  663  664  665  666  667  668  669  670  671  673  674  675  676  677  678  680 
#>   36   16    7   10   93   70    3   13    2   41   52   40   10    7    9    7 
#>  681  682  683  684  685  686  687  688  689  690  691  693  694  696  697  698 
#>   23   14   12   15   21    7   17    6    1    4    2   28   23    4   61   15 
#>  699  701  702  703  704  705  706  708  709  710  711  713  714  716  717  719 
#>   65    1   35   45    5    1   18   23   19    4   58   51   30   25   17   14 
#>  720  721  722  723  725  726  727  728  729  730  731  732  733  734  735  736 
#>   20   14    7   12   39    5    1   12  101   11    3   11    2   45   26   13 
#>  738  739  740  741  742  743  744  745  746  747  748  749  750  751  753  754 
#>    2    2   16   27   10    3    3    4   44   23    1   55   89    3   27   32 
#>  755  756  757  758  760  761  763  764  765  766  767  768  769  770  771  772 
#>    3    7   12    2   61  134   28   27   22    7    1   20    4   16   22   40 
#>  773  776  777  778  779  781  782  783  784  785  786  787  788  789  790  791 
#>   43    3   16    5    5    6   16   12    5   59   85    7    3    1   27   24 
#>  792  793  794  795  796  797  798  799  800  801  803  804  805  806  808  809 
#>   37   22   11    6   14    3    5   13    2    7   22    1   25    6   28   29 
#>  810  811  812  813  814  815  816  817  818  819  820  822  823  824  825  826 
#>   16    1   14    8    7   25    2    4   26   53   61   20    8   30   13   58 
#>  827  828  829  830  831  832  834  835  836  837  839  840  842  843  844  845 
#>  113   27   59   31   58   13   84    1  386   35   21   30   20   11   20    5 
#>  846  847  849  850  851  852  853  854  857  858  859  860  861  862  863  864 
#>   13   26    6  175   11   42   63    4   14   28    7   35    4   13   10   63 
#>  865  866  867  868  869  870  871  872  873  874  875  876  877  878  879  880 
#>   19   27   18   39   27    2    5    9   47   40  114   25   10    9   14   11 
#>  881  882  883  884  885  887  888  889  890  892  893  894  895  896  897  898 
#>    5   21   15   13    6    2   34    2    7   55  212    3  144   13    7    5 
#>  899  900  901  902  903  904  905  906  907  908  909  910  913  914  915  916 
#>   25   17   17   51   20   10   19   46    5    2   27   22    4   11    4   31 
#>  918  919  920  921  922  923  924  925  926  927  928  929  932  933  934  935 
#>   97   69   21   22   78    9   38   23    5    3    2   27   48   11   18   10 
#>  937  938  939  941  942  943  949  952  953  954  957  958  959  961  962  963 
#>    9   11   26    2   31    5   11    2    6   15    6    2    5    8    8    7 
#>  970  975  976  977  978  981  982  983  985  987  988  991  992  997  999 1000 
#>    2    2    5    2   13    2    5    1   42    3    6    1    1   13    6   11 
#> 1001 1004 1005 1006 1007 1008 1010 1011 1013 1015 1017 1019 1027 1028 1029 1031 
#>    2    3    6    5   36    1   19    3   10    9   18   25    2    1    8   22 
#> 1032 1033 1034 1037 1038 1039 1040 1041 1043 1045 1046 1049 1051 1056 1061 1062 
#>   31    1    6    1    5   42   11    2    5   42    6   16    6    1   13    8 
#> 1066 1068 1069 1074 1078 1079 1080 1083 1085 1087 1090 1092 1093 1094 1095 1096 
#>    5  144  329   17    7    5    7    1    8   19   13   16    3   18   19   11 
#> 1097 1100 1102 1103 1106 1108 1109 1110 1111 1112 1114 1117 1120 1124 1125 1127 
#>    7  211    4   11    4  173    3   32    5   18    8  134   55    5    1    3 
#> 1128 1131 1134 1135 1136 1138 1139 1140 1141 1142 1143 1144 1145 1147 1149 1150 
#>    3   82   41   35    7   11   56    2   45   23   14   27    2    4  100   31 
#> 1151 1153 1154 1155 1157 1159 1161 1162 1164 1165 1166 1167 1168 1169 1171 1173 
#>   12  145    1   45    3    1    4   16    2   20    4   11    6   10    3   10 
#> 1174 1176 1178 1179 1183 1184 1186 1187 1189 1191 1192 1193 1194 1201 1203 1204 
#>    4    8  165   15    5    1    1    9   16    2   41   13    4   24    9    8 
#> 1205 1206 1210 1212 1213 1215 1218 1219 1220 1222 1227 1235 1237 1241 1244 1247 
#>    4    8   31    1    7    5    2   15    1    4   25   39    7    1    6    1 
#> 1251 1252 1256 1261 1263 1267 1270 1272 1275 1277 1284 1287 1288 1291 1294 1299 
#>    8    5   46    4    9   32    1    3    1    2   34    9    8   31   25   29 
#> 1302 1309 1313 1317 1322 1325 1328 1335 1339 1340 1341 1350 1351 1354 1361 1372 
#>    6    3    1   10    7   28   12   66    1    5    2   28   44    2   32    1 
#> 1387 1391 1392 1393 1396 1398 1400 1402 1403 1404 1406 1409 1410 1414 1415 1423 
#>    4   19    9   14   43   12    2    4   14  117   26    1    7    9    1   12 
#> 1424 1430 1432 1446 1449 1452 1453 1463 1472 1473 1475 1481 1482 1483 1484 1485 
#>   21    2    7    5    2    2   20   21    8    4    5   82    2   37    4    1 
#> 1487 1491 1520 1522 1524 1525 1530 1534 1536 1537 1546 1551 1552 1562 1568 1569 
#>   13    2    7    2    1   42   21    1    3   61   16    3    7   16   89   59 
#> 1570 1583 1584 1595 1605 1607 1613 1625 1626 1629 1634 1643 1651 1665 1668 1674 
#>   36    1    5    5    2   17   20    3   33  133    1   91    6   10    6   17 
#> 1688 1705 1722 1735 1744 1772 1780 1794 1820 1838 1844 1847 1850 1866 1867 1869 
#>   16   12    2    8    6    4   33    4    4   13   37   93   12   71    1   42 
#> 1886 1890 1896 1918 1922 1929 1939 1971 1984 1986 2006 2009 2012 2018 2027 2030 
#>   77   50   36    5   23    5   25   32   83   35    6   10    3   27    2   14 
#> 2034 2044 2064 2073 2079 2088 2089 2095 2097 2099 2100 2103 2109 2115 2117 2119 
#>    7    1   13   12    2    6    2   12   18   41   12   23    2    3   12    1 
#> 2123 2127 2140 2146 2148 2150 2156 2160 2172 2177 2220 2308 2316 2324 2334 
#>    2   17    1    1   38    8    2    4   10    6    2    2    1   11    5 
#> 3 least connected regions:
#> 10690 11508 23955 with 1 link
#> 5 most connected regions:
#> 1838 1839 2397 16552 21929 with 2334 links
#> [1] "Done"
#> [1] "Critical threshold is: 485.742261911301m"
#> Neighbour list object:
#> Number of regions: 23840 
#> Number of nonzero links: 8979138 
#> Percentage nonzero weights: 1.579873 
#> Average number of links: 376.6417 
#> Link number distribution:
#> 
#>    1    2    4    5    6    7    8    9   11   12   13   15   17   18   19   20 
#>    2    4    2    5    2    7    5    3   10   21    4    6   15   13    2   11 
#>   21   22   23   24   25   26   27   28   29   30   31   32   33   34   35   36 
#>    1    2    4   26    2    7   38   10    2   20   10    5   17   11   28    6 
#>   37   38   40   42   43   44   45   46   47   48   49   50   51   52   53   54 
#>   25   11    1    6    2   24    1   13   15   30   18    5   12   38   13   14 
#>   55   56   57   58   59   60   61   62   63   64   65   66   67   68   69   70 
#>   16    9    7   13    5   17    1    5   10   20   12    8   10    7    9   14 
#>   71   72   73   74   75   76   77   78   79   80   81   82   83   84   85   86 
#>   10   11   13    7    4   10   18   38   18   21    8   26   15    1    4    8 
#>   87   88   89   90   91   92   93   94   95   96   97   98   99  100  101  102 
#>   27   22   10   24   52   36   19   20    7   34   30   20   29   23   28   36 
#>  103  104  105  106  107  108  109  110  111  112  113  114  115  116  117  118 
#>   16   36   31   27   21   13   36   26   42   20    9   32   14   15    8   21 
#>  119  120  121  122  123  124  125  126  127  128  129  130  131  132  133  134 
#>   32   35    9   20   53   25   47   54   20   36   37   30   40   30   21   14 
#>  135  136  137  138  139  140  141  142  143  144  145  146  147  148  149  150 
#>   13   44   39   43   28   24   54   54   56   78   11   28   35   38   50   41 
#>  151  152  153  154  155  156  157  158  159  160  161  162  163  164  165  166 
#>   57   38   36   34   28    9   26   12   52   45   24   19   21   37   28   38 
#>  167  168  169  170  171  172  173  174  175  176  177  178  179  180  181  182 
#>   44   23   43   19   40   21   35   55   49   58   27  114   34   68   19   69 
#>  183  184  185  186  187  188  189  190  191  192  193  194  195  196  197  198 
#>   23   27   70   24   63   37   78   32   43   76   72   72   50   37   21   34 
#>  199  200  201  202  203  204  205  206  207  208  209  210  211  212  213  214 
#>   31   40   48   42   34    9   40   66   29   37   31   39   31   82   16   92 
#>  215  216  217  218  219  220  221  222  223  224  225  226  227  228  229  230 
#>   72   58   38   63   56   26   88   82   56   73   78   62   87   44   58   38 
#>  231  232  233  234  235  236  237  238  239  240  241  242  243  244  245  246 
#>   45   66   65   33   33   77   36   27  104   78   70   52   45   90   36   66 
#>  247  248  249  250  251  252  253  254  255  256  257  258  259  260  261  262 
#>   57   73   61   63   20   40   82   37   35   29   17   43   20   10   24   79 
#>  263  264  265  266  267  268  269  270  271  272  273  274  275  276  277  278 
#>   20   44   72   39  108    6   40   15   23   58   37   33  124   52   45   52 
#>  279  280  281  282  283  284  285  286  287  288  289  290  291  292  293  294 
#>   33    6   50   47   61   45   33   39   95   81   24   30   43   77  149   30 
#>  295  296  297  298  299  300  301  302  303  304  305  306  307  308  309  310 
#>   22   80    8   29   75   36   41  118   35   42   72   25   34   14   35   43 
#>  311  312  313  314  315  316  317  318  319  320  321  322  323  324  325  326 
#>   60   57   22   29   76   40   36   21   36   42   61   33    6   35   21   60 
#>  327  328  329  330  331  332  333  334  335  336  337  338  339  340  341  342 
#>   17   23   54   67   78   26   52   65   16   52   31   60   87   64   48   42 
#>  343  344  345  346  347  348  349  350  351  352  353  354  355  356  357  358 
#>   22   37   42   39   64    3   38   34   85   88   24   54   43   93   71   30 
#>  359  360  361  362  363  364  365  366  367  368  369  370  371  372  373  374 
#>   36   33   34   71   87   35   47   55   65   28   41   39  103   49   13   99 
#>  375  376  377  378  379  380  381  382  383  384  385  386  387  388  389  390 
#>   31   52   12   16   39   13   67   27   12   39   29   25   11   28    6   46 
#>  391  392  393  394  395  396  397  398  399  400  401  402  403  404  405  406 
#>   41   69   34   23   71  136   31   14  117   58   19   34    5   19   40   34 
#>  407  408  409  410  411  412  413  414  415  416  417  418  419  420  421  422 
#>   17   15   34   10   41    5   45   27   61   10   73   67   23   24   43   49 
#>  423  424  425  426  427  428  429  430  431  432  433  434  435  436  437  438 
#>   26   51    8   35   63   30   73   16   19   37   17   69   17   24   39    6 
#>  439  440  441  442  443  444  446  447  448  449  450  451  452  453  454  455 
#>   32   51   68   59   45   14   27    8   27   30    8   22   12   33   10   16 
#>  456  457  458  459  460  461  462  463  464  465  466  467  468  469  470  472 
#>    6   29   59   12   45    8    5   51  106   63   24   19   60   14   18    8 
#>  473  474  475  476  477  478  479  480  481  482  483  484  485  486  487  488 
#>   23    5   40   16    4    5   36   47   11   22    5   31   12   45   30   25 
#>  489  490  491  492  493  494  495  496  497  498  500  501  502  503  504  505 
#>   14    8   45    4   43   37   27   48   21    9   29   15   69   13   16   11 
#>  506  507  508  509  510  511  512  513  514  515  516  518  519  520  521  522 
#>   18   27   45   33   18   29   16   20   48   31    5   24   23   11   37   40 
#>  523  524  525  526  527  528  529  530  531  532  533  534  535  536  537  538 
#>   15   31   28    4   22   13   37    9   17   13    8   33   25    3   11   35 
#>  539  540  541  542  543  544  545  547  548  550  551  552  553  554  555  556 
#>   10   33   88   12   52    6    9   37   10    4   16   16   69   15    8   29 
#>  557  558  559  561  562  563  564  565  566  568  570  573  574  575  576  577 
#>   27  122   42   12  420    4    3   15   49   20    7    8   13    6   39   71 
#>  578  579  580  581  582  583  584  585  586  587  588  589  590  591  592  594 
#>   15   10   23   15   33   62   13   17   30    9   77    2    4   29   25   51 
#>  595  596  597  598  599  600  601  602  603  604  605  606  608  609  610  611 
#>   39   45    7    9   15   19   18   12   99   26   10   43    4   55   17   14 
#>  612  613  614  615  616  617  618  619  620  621  622  623  624  625  627  628 
#>   22   11   17    2  147   20   23   15   27   88   75  143   57   14   50   37 
#>  629  630  631  632  633  634  635  637  638  639  640  641  642  643  644  646 
#>   26   11   53   20   14   11   24   13   35   21   42   12   32   22   12   43 
#>  649  650  652  653  654  655  656  657  658  659  660  661  667  668  669  670 
#>   31   76   10   14   27    1   13    6   25   14    8    7    9    4   24    7 
#>  671  672  674  675  676  677  678  679  680  681  682  683  684  685  687  688 
#>    6   22    4   44   21    8   48   14   64   13   45   22   19    5   46    2 
#>  690  691  692  693  694  696  697  699  700  702  703  707  708  709  710  711 
#>   13   31    8   41    5   25   11    5    4   19   37   21   10   35   24   18 
#>  712  713  714  715  716  717  718  720  721  722  725  727  728  729  730  732 
#>   24    3    1    2    6    1    4   10   33   24   30   23   19   21    4    3 
#>  733  734  735  739  741  742  744  745  746  747  748  749  752  753  755  756 
#>   24   11    3   17   22   13   11   10    8   90   27   21   10   44   24   26 
#>  758  759  760  764  765  767  768  770  771  774  777  780  783  784  785  787 
#>   32    6   26   13    5   13    4   15    3    7    2   18    6    4    3   38 
#>  789  791  797  799  801  804  807  809  810  811  814  822  826  828  829  832 
#>    8   10    1   20   18    8    2   60   15   55   15   24   10    8    2  136 
#>  834  835  836  838  840  842  845  846  851  853  856  867  870  872  875  884 
#>    4    4    4    6    6    5    2    3    2    6    1    1    3   17   11    2 
#>  888  920  925  945  947  968  973  982 1026 1046 1047 1065 1088 1090 1092 1097 
#>    3    6   49    2   11   18    4    9    2    1   12    6    4    7   10   23 
#> 1098 1105 1106 1109 1110 1124 1136 1172 
#>   21   12    4    3    2    8    3    1 
#> 2 least connected regions:
#> 17957 23091 with 1 link
#> 1 most connected region:
#> 6729 with 1172 links
#> [1] "Done"
#> [1] "Critical threshold is: 604.717806803019m"
#> Neighbour list object:
#> Number of regions: 9045 
#> Number of nonzero links: 2044716 
#> Percentage nonzero weights: 2.499285 
#> Average number of links: 226.0604 
#> Link number distribution:
#> 
#>   1   2   3   5   6   7   9  10  11  12  13  14  15  16  17  18  19  20  21  22 
#>   3   3   2   1   2   3   4   4   6   7  21   9  10   4   3  11  12   6   6  29 
#>  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42 
#>   2   3   3   9   4   8  11   5   1   8  22   7   9   3  13   9  13  11   5  13 
#>  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62 
#>  12  14   7  16  16  20   3  15  15  16  27  19  22  10  45  24  31  18  20  17 
#>  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82 
#>  29  16  18  25  24  13  17  22  16   9  15  22  12  28   4  20  16  17  20   6 
#>  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 
#>  20  38  10  24  14  19  15  12  22  37  13  11  11   8   9  17  47  24  10  14 
#> 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 
#>  22  16  57  31  19  37   9  12  16  12  17  13  31  26  15  65  71  46  27  36 
#> 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 
#>  74  69  22  22  30  31  21  14  32  26  15  32  56  13  87  25  39  23  20  38 
#> 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 
#>  19  24  27  27  52  23  42  11  20  44  49  48  24  34  15  29  71  29  28  48 
#> 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 
#>   6  28  26  12  12  30  28  27  19  11  46  12  32  28  68  22  23  29  31  17 
#> 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 
#>  12  16  34  25  34  11  26  45  18  11  36  32  50  13  10  58 116  13  38  27 
#> 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 
#>  66  16  33  44  22  12  13  17  50  54  56  16  17  68  28  80  22  23  39  71 
#> 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 
#>  13  12   9  16  32   6  25   4  20  21  20  14   8  21   9   6  25  34  15  17 
#> 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 
#>  22  36  90  22  11  19  44  78  93  19  18  30  50  10  16   8  42  29  12  42 
#> 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 
#>  17  26  13  29  30   2  16  13  34  30   7  12  23  25   6  15  31  10   6  26 
#> 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 
#>  25   2  16  16  11  15   9  37  21  17  35  15   1  40   8  10   6  13   5  25 
#> 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 
#>   1  19  22  35  29   1   8   4   8   4   1   2  22   3   1   6   9   8  18  15 
#> 323 324 325 326 327 328 329 330 331 332 334 335 337 338 340 341 342 343 346 347 
#>  25   5  35   1  13   6   1   7   7   9  23   1  16   1   2   1   2   3   1   3 
#> 348 349 350 352 353 354 356 357 358 360 361 365 366 367 368 370 372 376 380 381 
#>   1   1   2  10   2   1   9   2   2   1   1   3   2   1   6   1   2   1   1   2 
#> 383 384 385 386 389 390 391 392 393 394 395 396 397 398 399 401 402 403 405 406 
#>   1   1   6   1   2   1   2   1   7  21   9   3   8   5   4   4   4   1   3   8 
#> 407 408 409 410 411 412 414 415 416 417 418 419 420 421 422 423 425 427 428 429 
#>   1   4   2   3   1  80   6   5   4   4   2   4  17   2   2 125   8  22   4   8 
#> 430 431 432 434 435 436 437 438 440 441 442 443 444 445 446 447 448 449 450 451 
#>   3   2  19 227  29  13  91 120   4  28  60  47 104  12  50  13  58  87   1   1 
#> 452 453 454 455 456 457 459 460 461 462 464 465 467 468 471 472 474 476 477 479 
#>   8  27   9   4  20  30   5  21   3  14   6   6  26   5   1   6  38  22   1   1 
#> 480 481 482 483 487 489 492 493 494 495 497 498 500 502 510 517 519 522 547 552 
#>   6   7   6   8   4   7   2   3   1   5   2   2   2   5   5   4   1   1   4   1 
#> 3 least connected regions:
#> 307 7432 7459 with 1 link
#> 1 most connected region:
#> 1782 with 552 links
#> [1] "Done"
#> [1] "Critical threshold is: 573.015350706016m"
#> Neighbour list object:
#> Number of regions: 13516 
#> Number of nonzero links: 3148774 
#> Percentage nonzero weights: 1.723634 
#> Average number of links: 232.9664 
#> Link number distribution:
#> 
#>   5   6   7  11  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28 
#>   9   2   1   8   6   4   4   4   1  18  11   7   9   2   7   6  10   1   2   3 
#>  29  30  31  33  35  36  37  38  39  40  41  42  44  45  46  47  48  49  50  51 
#>   2   1   1   8   4   6   5   1   2  14   4  10   4   2  12   1  12   3   6  11 
#>  52  53  54  55  56  57  58  59  60  61  63  64  65  66  67  68  69  70  71  72 
#>  24  18   9   1   4   7  12   4   6   4   3   5   1  13  17   2   2  13   4   1 
#>  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92 
#>  20  22  24  15  10   1   9  17  11  15  18  18  14  12   4  19  12   3  38  60 
#>  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 
#>  26  28  30  14  12   9  14  14  27  23  23  22   9  28  20  36  30  27  46  37 
#> 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 
#>  34  23  15  18  58  27  27  24  32  42  33  43  39  28  31  20  30  49  47  43 
#> 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 
#>  34  47  35  70  41  54  52  91  41  54  38  53  38  35  62  36  36  22  60  30 
#> 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 
#>  41  60  54  76  32  37  56  70  35  46  37  44  59  38  26  75  44  40  16  39 
#> 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 
#>  43  79  59  54  85  46  50  47  32  35  44  86  64  60  78  68  46  53  48  40 
#> 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 
#>  56  46  32  59  64  37  33  34  31  51  64  37  55  44  52  68  43  88  55  55 
#> 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 
#>  60  89  80  35  52 131  58  42  59  34  60  64  95  60  69  52  35  55  71  55 
#> 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 
#>  58  56  59  94  49  83  54  60  32  40  90  46  43  49  51  18  68  61  55  31 
#> 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 
#>  50  52  55  36  59  85  89  81  76  72  53  43  32  45  70  65  39  48  55 145 
#> 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 
#>  27  37  28  69  51  34  58  64  38  75  47  51  31  62  85  28  47  59  46  33 
#> 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 
#>  46  35  46 104  58  44  42  16  31  33  20  43  34  36  70  11  31  23  60  22 
#> 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 
#>  43  17  30  24  44  56   7  26  31  22  43  15  31  15  35  19  26   6  47   5 
#> 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 
#>  13   7   8  45  24   9   6  11   9  15  17  16   7  13   2   4   2   2  73   6 
#> 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 
#>  26   3   1   6   2  15  23  17   7   5   7   4   7   6   9   2   2   2  16   4 
#> 374 375 376 377 378 379 381 382 384 387 391 395 396 397 398 399 402 403 405 406 
#>   3  54   5   8   4   5   7  33  16  64  11   5  14  21   2   1   5  99   6   1 
#> 408 409 410 412 413 415 416 417 418 419 420 421 422 423 424 425 426 427 428 430 
#>   2   5   8   2  12  83   7  41   4   4 127  11   5   8   9  10  21   1  14   4 
#> 431 432 434 435 436 437 438 439 440 441 446 449 450 451 452 453 454 456 459 460 
#>   2 178  14  12  20  13   7   2  10   3  23   2   1   6   1   1   8   5 126   5 
#> 462 464 465 470 478 479 480 481 484 485 488 490 492 501 502 506 507 514 515 530 
#>  11   8  25   2   8   2   2  12   4   3   2   6   5   2   7   1   1   2   3   1 
#> 591 601 607 608 614 616 626 
#>   3   6   4   4   1   3   5 
#> 9 least connected regions:
#> 59 524 804 4734 5688 6163 8531 9728 10399 with 5 links
#> 5 most connected regions:
#> 1057 1679 2251 2587 4286 with 626 links
#> [1] "Done"
#> [1] "Critical threshold is: 915.135151068049m"
#> Neighbour list object:
#> Number of regions: 2601 
#> Number of nonzero links: 597862 
#> Percentage nonzero weights: 8.837313 
#> Average number of links: 229.8585 
#> Link number distribution:
#> 
#>   1   2   3   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22 
#>   2   1   1   2   1   5   2   6   5   5   6  11   5   9   8   5   3   6  14   4 
#>  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42 
#>   3  14   5   8   4   2   5   4   2   2   4   6   8  17   9  13   6  11   4   5 
#>  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62 
#>   2   8   4   6   4   9  11  38  10   6   5  11   8  11   3  12  19  19   5   9 
#>  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82 
#>   9   3   4   5   1   6  19   3  12   9   4  21   2   5  12  11   6   3  24   8 
#>  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 
#>  28  19  25  11   5  10  11  22   7  14  51   6   3   4   2   2   4   4   4   4 
#> 103 104 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 
#>  10   5   3   3  11  11   1   2   1   8   1   2   3   6   1   4  31  14   6   3 
#> 124 125 126 127 128 129 130 131 132 133 134 135 136 137 139 141 142 146 147 149 
#>  11  39  11  21   4  21   5  41   8   7   2   3   5   1   4   2   1   3   1   5 
#> 151 152 155 156 157 158 161 164 165 169 170 174 176 178 181 182 183 184 185 186 
#>   2   1   2   2  58   1   1   2   3   1   1   1   3   2   3   2  63  41  18  11 
#> 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 
#>   8  16  16  23  39  30   5   1   1  10   4  31  27  30   2   6  16   6   1   2 
#> 210 212 213 216 217 218 220 221 224 227 228 229 232 259 283 285 369 370 381 385 
#>   2   2   1   8   1   4   6   2   3   1   2   1  11   2   1   1   1   2   2   1 
#> 387 391 392 402 403 404 405 406 407 409 412 413 414 416 422 425 428 429 430 433 
#>   1  10   1   1   2   1   1  15   7   1   1   1   4  12   1   1   1   3   2  32 
#> 434 435 436 438 439 440 442 443 445 446 447 448 449 450 451 453 454 456 457 459 
#>   2   5  31   6   3   2   5   1   3   3   1  84  70  37  30 133 120 223   1   7 
#> 462 464 468 469 474 480 489 517 526 532 
#>   1   1   5   1   1   2  15   4   2   1 
#> 2 least connected regions:
#> 753 1769 with 1 link
#> 1 most connected region:
#> 606 with 532 links
#> [1] "Done"
#> [1] "Critical threshold is: 460.915689137396m"
#> Neighbour list object:
#> Number of regions: 6767 
#> Number of nonzero links: 613462 
#> Percentage nonzero weights: 1.339662 
#> Average number of links: 90.65494 
#> Link number distribution:
#> 
#>   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20 
#>   5   6   3   2   9   4  18   4   6  19  17  23   6  16   3  23  12  19  16  16 
#>  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40 
#>  17  21  20  38  23  41  42  33  24  28  43  41  69  59  63  33  49  35  58  41 
#>  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60 
#>  52  56  37  58  54  82  33  44  47  56  69  64  62  54  72  75  36  36  54  43 
#>  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80 
#>  46  63  47  68  62  51  47  61  57  41  62  50  55  46  54  79  89  78  73  44 
#>  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 
#>  53  83  92  67  80 100  61  82  80  63  58  75  55  45  41  39  37  55  66  33 
#> 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 
#>  26  45  21  47  40  37  60  34  34  16  23  21  19  38  31  29  37  46  11  28 
#> 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 
#>  37  33  13  56  19  26  43  20  15   2  26  28   6   9  26   6  25  25   3  28 
#> 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 
#>  51  40  10  28  22  17  15   9  22  24  10  13  25   5  12  21  24  12   5  31 
#> 161 162 163 164 165 166 167 168 169 170 171 172 173 175 176 177 178 179 180 181 
#>   8   7  29   6   8  19   1  19  20   2  10   9  13  29  27  14   3   9  14  19 
#> 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 
#>   8   4   9   9  11  32  12  16  14   2   2   7  15   6   3  10   9   5  41   9 
#> 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 220 222 223 225 226 
#>   2   1   7   7   3  10   1   8  43  10   7   3  17   2   5   3   1  22   2   5 
#> 228 230 233 234 235 236 237 238 240 241 242 243 247 
#>   5   8  34   1   2   2   1  11  14  11   1  10   6 
#> 5 least connected regions:
#> 512 1076 1208 1620 4240 with 1 link
#> 6 most connected regions:
#> 5 430 1177 1853 2377 2679 with 247 links
#> [1] "Done"

Count the Number of Neighbouring Points of Each Crime Point within 100m

Example with ASB

Code
#--Count 
counts_asb <- numeric(nrow(asb))

for (i in seq_along(asb)){
  #--Get a ponit 
  point <- asb[i,]$geometry
  
  #--Get buffer basically area within 100m 
  buffer <- st_buffer(point, units::as_units(100, "m"))
  
  #--Test if the asb points intersect with buffer
  test <- st_intersects(asb$geometry, buffer)

  #--Calculate the number of points intersecting buffer
  n <- which(sapply(test, function(x) sum(x) != 0)) |> length()

  #--Exclude the point itself
  counts_asb[i] <- n - 1
}

#--Assign the counts to the 'count' column of the spatial points object
asb$count <- counts_asb

#--Check the structure of 'asb' to ensure the count variable is added correctly
summary(asb)
#>    category               id               month           location_type     
#>  Length:25551       Min.   : 91710306   Length:25551       Length:25551      
#>  Class :character   1st Qu.: 97081088   Class :character   Class :character  
#>  Mode  :character   Median :103280983   Mode  :character   Mode  :character  
#>                     Mean   :103443093                                        
#>                     3rd Qu.:109502752                                        
#>                     Max.   :116586465                                        
#>  location_subtype   location.street.id location.street.name
#>  Length:25551       Min.   : 923463    Length:25551        
#>  Class :character   1st Qu.: 980725    Class :character    
#>  Mode  :character   Median :1661421    Mode  :character    
#>                     Mean   :1336059                        
#>                     3rd Qu.:1667149                        
#>                     Max.   :1677900                        
#>           geometry         count         
#>  POINT        :25551   Min.   :0.00e+00  
#>  epsg:27700   :    0   1st Qu.:0.00e+00  
#>  +proj=tmer...:    0   Median :0.00e+00  
#>                        Mean   :9.43e-03  
#>                        3rd Qu.:0.00e+00  
#>                        Max.   :1.03e+02

Repeat

Define Function: count_crime()
Code
count_crime <- function(crime, radius){
  #--Count 
  counts <- numeric(nrow(crime))

  for (i in seq_along(crime)){
    #--Get a point 
    point <- crime[i,]$geometry
    
    #--Get buffer basically area within the specified radius
    buffer <- st_buffer(point, units::as_units(radius, "m"))
    
    #--Test if the crime points intersect with buffer
    test <- st_intersects(crime$geometry, buffer)

    #--Calculate the number of points intersecting buffer
    n <- which(sapply(test, function(x) sum(x) != 0)) |> length()

    #--Exclude the point itself
    counts[i] <- n - 1
  }

  #--Assign the counts to the 'count' column of the spatial points object
  crime$count <- counts
  print("Done")
  return(crime)
}
Loop
Code
#--Count crime within 100m radius
l_crime <- map(l_crime, ~count_crime(.x, 100))
#> [1] "Done"
#> [1] "Done"
#> [1] "Done"
#> [1] "Done"
#> [1] "Done"
#> [1] "Done"

Perform Global Autocorrelation Test

Example with ASB

Code
# Conduct global Moran's I analysis
set.seed(1234)
moran_asb <- spdep::moran.test(asb$count, listw = dist_weight_asb)
  # using the count of ASB crimes within 100m of each point as the variable to assess for global spatial autocorrelation

# --Print Moran's I test results
print(moran_asb) 
#> 
#>  Moran I test under randomisation
#> 
#> data:  asb$count  
#> weights: dist_weight_asb    
#> 
#> Moran I statistic standard deviate = 2.6573, p-value = 0.003939
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>      6.969130e-04     -3.913894e-05      7.672758e-08
  # weak positive autocorrelation, that is, nearby points tend to have similar values

Repeat

Code
l_moran <- vector("list", length(l_crime))
l_moran <- map2(.x = l_crime, .y = l_weight, .f = ~spdep::moran.test(.x$count, listw = .y))

lapply(l_moran, print)
#> 
#>  Moran I test under randomisation
#> 
#> data:  .x$count  
#> weights: .y    
#> 
#> Moran I statistic standard deviate = 2.6573, p-value = 0.003939
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>      6.969130e-04     -3.913894e-05      7.672758e-08 
#> 
#> 
#>  Moran I test under randomisation
#> 
#> data:  .x$count  
#> weights: .y    
#> 
#> Moran I statistic standard deviate = -0.32804, p-value = 0.6286
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>     -1.647028e-04     -4.194807e-05      1.400344e-07 
#> 
#> 
#>  Moran I test under randomisation
#> 
#> data:  .x$count  
#> weights: .y    
#> 
#> Moran I statistic standard deviate = -0.17873, p-value = 0.5709
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>     -2.546378e-04     -1.105705e-04      6.496998e-07 
#> 
#> 
#>  Moran I test under randomisation
#> 
#> data:  .x$count  
#> weights: .y    
#> 
#> Moran I statistic standard deviate = 0.50015, p-value = 0.3085
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>      2.829501e-04     -7.399186e-05      5.093188e-07 
#> 
#> 
#>  Moran I test under randomisation
#> 
#> data:  .x$count  
#> weights: .y    
#> 
#> Moran I statistic standard deviate = 0.46265, p-value = 0.3218
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>      6.284823e-04     -3.846154e-04      4.794996e-06 
#> 
#> 
#>  Moran I test under randomisation
#> 
#> data:  .x$count  
#> weights: .y    
#> 
#> Moran I statistic standard deviate = 1.1177, p-value = 0.1319
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>      1.929608e-03     -1.477978e-04      3.454662e-06
#> $asb
#> 
#>  Moran I test under randomisation
#> 
#> data:  .x$count  
#> weights: .y    
#> 
#> Moran I statistic standard deviate = 2.6573, p-value = 0.003939
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>      6.969130e-04     -3.913894e-05      7.672758e-08 
#> 
#> 
#> $vc
#> 
#>  Moran I test under randomisation
#> 
#> data:  .x$count  
#> weights: .y    
#> 
#> Moran I statistic standard deviate = -0.32804, p-value = 0.6286
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>     -1.647028e-04     -4.194807e-05      1.400344e-07 
#> 
#> 
#> $other
#> 
#>  Moran I test under randomisation
#> 
#> data:  .x$count  
#> weights: .y    
#> 
#> Moran I statistic standard deviate = -0.17873, p-value = 0.5709
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>     -2.546378e-04     -1.105705e-04      6.496998e-07 
#> 
#> 
#> $vhc
#> 
#>  Moran I test under randomisation
#> 
#> data:  .x$count  
#> weights: .y    
#> 
#> Moran I statistic standard deviate = 0.50015, p-value = 0.3085
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>      2.829501e-04     -7.399186e-05      5.093188e-07 
#> 
#> 
#> $tfp
#> 
#>  Moran I test under randomisation
#> 
#> data:  .x$count  
#> weights: .y    
#> 
#> Moran I statistic standard deviate = 0.46265, p-value = 0.3218
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>      6.284823e-04     -3.846154e-04      4.794996e-06 
#> 
#> 
#> $brg
#> 
#>  Moran I test under randomisation
#> 
#> data:  .x$count  
#> weights: .y    
#> 
#> Moran I statistic standard deviate = 1.1177, p-value = 0.1319
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>      1.929608e-03     -1.477978e-04      3.454662e-06

Only ASB points within 100m showed a weak positive spatial auto-correlation. We will then run the test again with a different set of radius for the buffer.

Pull Everything Together

Code
run_global_sa <- function(crime, radius, weight){
  # Count crime within the specified radius
  crime <- count_crime(crime, radius)
  print("Crime count added!")

  # Run global autocorrelation test
  set.seed(1234)
  moran <- spdep::moran.test(crime$count, listw = weight)
  print(moran)

  return(moran)
}

Loop run_global_sa() with different sets of radius

Code
c_radius <- c(50, 75, 200, 300)

l_moran_radius <- vector("list", length(l_crime)-1)
l_moran_radius <- map(l_moran_radius, ~vector("list", length(c_radius)))
names(l_moran_radius) <- names(l_crime)[2:6]

for (j in 2:length(l_crime)){
  for (i in seq_along(c_radius)){
    l_moran_radius[[(j-1)]][[i]] <- run_global_sa(
      crime = l_crime[[j]],
      radius = c_radius[[i]],
      weight = l_weight[[j]])
  }
}
#> [1] "Done"
#> [1] "Crime count added!"
#> 
#>  Moran I test under randomisation
#> 
#> data:  crime$count  
#> weights: weight    
#> 
#> Moran I statistic standard deviate = -0.36522, p-value = 0.6425
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>     -2.132557e-04     -4.194807e-05      2.200069e-07 
#> 
#> [1] "Done"
#> [1] "Crime count added!"
#> 
#>  Moran I test under randomisation
#> 
#> data:  crime$count  
#> weights: weight    
#> 
#> Moran I statistic standard deviate = -0.36437, p-value = 0.6422
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>     -1.774724e-04     -4.194807e-05      1.383394e-07 
#> 
#> [1] "Done"
#> [1] "Crime count added!"
#> 
#>  Moran I test under randomisation
#> 
#> data:  crime$count  
#> weights: weight    
#> 
#> Moran I statistic standard deviate = -0.36929, p-value = 0.644
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>     -2.114624e-04     -4.194807e-05      2.107093e-07 
#> 
#> [1] "Done"
#> [1] "Crime count added!"
#> 
#>  Moran I test under randomisation
#> 
#> data:  crime$count  
#> weights: weight    
#> 
#> Moran I statistic standard deviate = -0.40668, p-value = 0.6579
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>     -2.376532e-04     -4.194807e-05      2.315813e-07 
#> 
#> [1] "Done"
#> [1] "Crime count added!"
#> 
#>  Moran I test under randomisation
#> 
#> data:  crime$count  
#> weights: weight    
#> 
#> Moran I statistic standard deviate = -0.139, p-value = 0.5553
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>     -2.513731e-04     -1.105705e-04      1.026155e-06 
#> 
#> [1] "Done"
#> [1] "Crime count added!"
#> 
#>  Moran I test under randomisation
#> 
#> data:  crime$count  
#> weights: weight    
#> 
#> Moran I statistic standard deviate = -0.15471, p-value = 0.5615
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>     -2.484190e-04     -1.105705e-04      7.939177e-07 
#> 
#> [1] "Done"
#> [1] "Crime count added!"
#> 
#>  Moran I test under randomisation
#> 
#> data:  crime$count  
#> weights: weight    
#> 
#> Moran I statistic standard deviate = -0.2797, p-value = 0.6101
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>     -2.874777e-04     -1.105705e-04      4.000466e-07 
#> 
#> [1] "Done"
#> [1] "Crime count added!"
#> 
#>  Moran I test under randomisation
#> 
#> data:  crime$count  
#> weights: weight    
#> 
#> Moran I statistic standard deviate = -0.28403, p-value = 0.6118
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>     -3.152505e-04     -1.105705e-04      5.193188e-07 
#> 
#> [1] "Done"
#> [1] "Crime count added!"
#> 
#>  Moran I test under randomisation
#> 
#> data:  crime$count  
#> weights: weight    
#> 
#> Moran I statistic standard deviate = -0.10716, p-value = 0.5427
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>     -1.507892e-04     -7.399186e-05      5.136210e-07 
#> 
#> [1] "Done"
#> [1] "Crime count added!"
#> 
#>  Moran I test under randomisation
#> 
#> data:  crime$count  
#> weights: weight    
#> 
#> Moran I statistic standard deviate = -0.19079, p-value = 0.5757
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>     -2.058521e-04     -7.399186e-05      4.776522e-07 
#> 
#> [1] "Done"
#> [1] "Crime count added!"
#> 
#>  Moran I test under randomisation
#> 
#> data:  crime$count  
#> weights: weight    
#> 
#> Moran I statistic standard deviate = 0.71142, p-value = 0.2384
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>      4.972694e-04     -7.399186e-05      6.447957e-07 
#> 
#> [1] "Done"
#> [1] "Crime count added!"
#> 
#>  Moran I test under randomisation
#> 
#> data:  crime$count  
#> weights: weight    
#> 
#> Moran I statistic standard deviate = 0.39901, p-value = 0.3449
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>      2.450347e-04     -7.399186e-05      6.392625e-07 
#> 
#> [1] "Done"
#> [1] "Crime count added!"
#> 
#>  Moran I test under randomisation
#> 
#> data:  crime$count  
#> weights: weight    
#> 
#> Moran I statistic standard deviate = 1.2437, p-value = 0.1068
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>      2.546008e-03     -3.846154e-04      5.552078e-06 
#> 
#> [1] "Done"
#> [1] "Crime count added!"
#> 
#>  Moran I test under randomisation
#> 
#> data:  crime$count  
#> weights: weight    
#> 
#> Moran I statistic standard deviate = 1.1557, p-value = 0.1239
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>      2.362469e-03     -3.846154e-04      5.649864e-06 
#> 
#> [1] "Done"
#> [1] "Crime count added!"
#> 
#>  Moran I test under randomisation
#> 
#> data:  crime$count  
#> weights: weight    
#> 
#> Moran I statistic standard deviate = 0.65148, p-value = 0.2574
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>      1.217077e-03     -3.846154e-04      6.044352e-06 
#> 
#> [1] "Done"
#> [1] "Crime count added!"
#> 
#>  Moran I test under randomisation
#> 
#> data:  crime$count  
#> weights: weight    
#> 
#> Moran I statistic standard deviate = 0.59598, p-value = 0.2756
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>      1.096501e-03     -3.846154e-04      6.176107e-06 
#> 
#> [1] "Done"
#> [1] "Crime count added!"
#> 
#>  Moran I test under randomisation
#> 
#> data:  crime$count  
#> weights: weight    
#> 
#> Moran I statistic standard deviate = 0.53712, p-value = 0.2956
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>      8.495753e-04     -1.477978e-04      3.448102e-06 
#> 
#> [1] "Done"
#> [1] "Crime count added!"
#> 
#>  Moran I test under randomisation
#> 
#> data:  crime$count  
#> weights: weight    
#> 
#> Moran I statistic standard deviate = 0.59442, p-value = 0.2761
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>      9.260347e-04     -1.477978e-04      3.263568e-06 
#> 
#> [1] "Done"
#> [1] "Crime count added!"
#> 
#>  Moran I test under randomisation
#> 
#> data:  crime$count  
#> weights: weight    
#> 
#> Moran I statistic standard deviate = 1.3761, p-value = 0.0844
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>      2.521486e-03     -1.477978e-04      3.762654e-06 
#> 
#> [1] "Done"
#> [1] "Crime count added!"
#> 
#>  Moran I test under randomisation
#> 
#> data:  crime$count  
#> weights: weight    
#> 
#> Moran I statistic standard deviate = 1.3032, p-value = 0.09625
#> alternative hypothesis: greater
#> sample estimates:
#> Moran I statistic       Expectation          Variance 
#>      2.479044e-03     -1.477978e-04      4.062848e-06

Local Spatial Autocorrelation

Code
#--Perform Local Moran's I analysis
local_moran <- spdep::localmoran(asb$count, dist_weight_asb)
asb$morans_I <- local_moran[, 1]
asb$expected_I <- local_moran[, 2]
asb$p_values <- local_moran[,5]

asb <- asb |> 
  mutate(quadrant = case_when(
    morans_I > 0 & expected_I > 0 & p_values < 0.05 ~"High-High",
    morans_I < 0 & expected_I < 0 & p_values < 0.05 ~"Low-Low",
    morans_I > 0 & expected_I < 0 & p_values < 0.05 ~"High-Low",
    morans_I < 0 & expected_I > 0 & p_values < 0.05 ~"Low-High", 
    .default = "Not Significant"
  ))

asb$quadrant <- factor(asb$quadrant, levels = c("High-High", "Low-Low", "High-Low", "Low-High", "Not Significant"))

table(asb$quadrant) |>
  as.data.frame() |>
  flextable()

Var1

Freq

High-High

0

Low-Low

1,534

High-Low

4

Low-High

0

Not Significant

24,013

Code

#--Plot the spatial data with color encoding for Local Moran's I
ggplot() +
  geom_sf(data = asb, aes(colour = quadrant)) +
  geom_sf(data = bnt_shp, alpha = 0, lwd = 2) +
  theme_minimal() +
  labs(colour = "Quadrant") +
  ggtitle("Local Moran Cluster Map of ASB Points")

Code

pal_asb <- leaflet::colorFactor(palette = 'RdYlGn', asb$quadrant)

leaflet::leaflet(data = st_transform(asb, 4326)) |>
  leaflet::addTiles() |>
  leaflet::addCircles(
    color = ~pal_asb(quadrant),
    popup = ~month) |>
  leaflet::addLegend('bottomright',
            pal =pal_asb,
            values = ~quadrant,
            title = 'Local Moran Cluster of ASB',
            opacity = 0.7)

Footnotes

  1. Anselin, Luc & Piras, Gianfranco. (2009). Approaches Towards the Identification of Patterns in Violent Events, Baghdad, Iraq. 82.↩︎